// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

//创建数据库实例
const db=cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {

  let newStatus = event.newStatus;
  let orderId=event.orderId;

  let promise=await db.collection('orders').where({ orderId: orderId })
                    .update({ data: { status: newStatus}});
  if (promise.errMsg == "collection.update:ok") {
    //返回数据
    return {
      result: 'success',
      error: ''
    }
  }
  else {
    return {
      result: 'fail',
      error: '变更状态失败'
    }
  }
}